package cn.hywx.convert;

import java.util.List;

import cn.hywx.convert.beans.DocumentBean;

public class OfficeProducer implements Runnable {
	private OfficeQueue queue;
	// thread run flag
	private boolean runFlag = true;
	public static long PRODUCT_DELAY = 3000;

	public OfficeProducer(OfficeQueue q) {
		this.queue = q;

	}

	@Override
	public void run() {
		while (runFlag) {
			List<DocumentBean> docBeans =  DocumentBean.getDocConvertQueue();
			if(docBeans!=null){
				try {
					for(DocumentBean docBean : docBeans){
						boolean pushRes = queue.pushDocument(docBean);
						if(pushRes){
							System.out.println("product:"+docBean);
						}
					}
					
				} catch (InterruptedException e1) {
					System.out.println("queue is waiting ...!");
					e1.printStackTrace();
				}
			}else{
				
			}
			
			try {
				Thread.sleep(PRODUCT_DELAY);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public boolean isRunFlag() {
		return runFlag;
	}

	public void setRunFlag(boolean runFlag) {
		this.runFlag = runFlag;
	}

}
